#ifndef __DETU_MEDIA_TYPES_H__
#define __DETU_MEDIA_TYPES_H__
#include "shared_ptr.h"
#include "types.h"
namespace detu_media
{

/*the nalu type of H264E*/
typedef enum _H264NaluType
{
    H264_NALU_BSLICE = 0,                         /*B SLICE types*/
    H264_NALU_PSLICE = 1,                         /*P SLICE types*/
    H264_NALU_ISLICE = 2,                         /*I SLICE types*/
    H264_NALU_IDRSLICE = 5,                       /*IDR SLICE types*/
    H264_NALU_SEI    = 6,                         /*SEI types*/
    H264_NALU_SPS    = 7,                         /*SPS types*/
    H264_NALU_PPS    = 8,                         /*PPS types*/
    H264_NALU_BUTT
} H264NaluType;

/*the nalu type of H265E*/
typedef enum _H265NaluType
{
    H265_NALU_BSLICE = 0,                          /*B SLICE types*/
    H265_NALU_PSLICE = 1,                          /*P SLICE types*/
    H265_NALU_ISLICE = 2,                          /*I SLICE types*/
    H265_NALU_IDRSLICE = 19,                       /*IDR SLICE types*/
    H265_NALU_VPS    = 32,                         /*VPS types*/
    H265_NALU_SPS    = 33,                         /*SPS types*/
    H265_NALU_PPS    = 34,                         /*PPS types*/
    H265_NALU_SEI    = 39,                         /*SEI types*/
    H265E_NALU_BUTT
} H265NaluType;

/*the pack type of JPEGE*/
typedef enum _JpegPackType
{
    JPEG_PACK_ECS = 5,                            /*ECS types*/
    JPEG_PACK_APP = 6,                            /*APP types*/
    JPEG_PACK_VDO = 7,                            /*VDO types*/
    JPEG_PACK_PIC = 8,                            /*PIC types*/
    JPEG_PACK_BUTT
} JpegPackType;

/*the pack type of PRORES*/
typedef enum _ProResPackType
{
    PRO_RES_PACK_PIC = 1,                            /*PIC types*/
    PRO_RES_PACK_BUTT
} ProResPackType;

typedef union _DataType
{
	H264NaluType 	h264Type;
	JpegPackType 	jpegType;
	H265NaluType 	h265Type;
	ProResPackType 	proResType;
} DataType;

typedef enum _EncodeType
{
	H264,
	H265,
	JPEG,
	MJPEG,
	PRORES
} EncodeType;

typedef struct _Resolution
{
	Uint32_t	width;
	Uint32_t	height;
} Resolution;

typedef struct _StreamInfo
{
	Uint32_t 	size;
	Uint64_t 	pts;
	EncodeType 	encodeType;
	DataType dataType;
} StreamInfo;

typedef struct _FrameInfo
{
	bool		multiPack;
	Uint32_t 	size;
	Int32_t		frameRate;
	Resolution	resolution;
	Uint64_t 	pts;
	EncodeType 	encodeType;
	DataType 	dataType;
	Uint32_t	dataNum;
	Uint32_t	dataSize[8];
	Uint8_t		*data[8];
	Uint8_t		*buf;
} FrameInfo;

typedef enum _MOD_ID_E
{
    DT_ID_CMPI    = 0,
    DT_ID_VB      = 1,
    DT_ID_SYS     = 2,
    DT_ID_RGN      = 3,
    DT_ID_CHNL    = 4,
    DT_ID_VDEC    = 5,
    DT_ID_AVS     = 6,
    DT_ID_VPSS    = 7,
    DT_ID_VENC    = 8,
    DT_ID_SVP     = 9,
    DT_ID_H264E   = 10,
    DT_ID_JPEGE   = 11,
    DT_ID_MPEG4E  = 12,
    DT_ID_H265E   = 13,
    DT_ID_JPEGD   = 14,
    DT_ID_VO      = 15,
    DT_ID_VI      = 16,
    DT_ID_DIS     = 17,
    DT_ID_VALG    = 18,
    DT_ID_RC      = 19,
    DT_ID_AIO     = 20,
    DT_ID_AI      = 21,
    DT_ID_AO      = 22,
    DT_ID_AENC    = 23,
    DT_ID_ADEC    = 24,
    DT_ID_VPU    = 25,
    DT_ID_PCIV    = 26,
    DT_ID_PCIVFMW = 27,
    DT_ID_ISP      = 28,
    DT_ID_IVE      = 29,
    DT_ID_USER    = 30,
    DT_ID_DCCM    = 31,
    DT_ID_DCCS    = 32,
    DT_ID_PROC    = 33,
    DT_ID_LOG     = 34,
    DT_ID_VFMW    = 35,
    DT_ID_H264D   = 36,
    DT_ID_GDC     = 37,
    DT_ID_PHOTO   = 38,
    DT_ID_FB      = 39,
    DT_ID_HDMI    = 40,
    DT_ID_VOIE    = 41,
    DT_ID_TDE     = 42,
    DT_ID_HDR      = 43,
    DT_ID_PRORES  = 44,
    DT_ID_VGS     = 45,

    DT_ID_FD      = 47,
    DT_ID_ODT      = 48, //Object detection trace
    DT_ID_VQA      = 49, //Video quality  analysis
    DT_ID_LPR      = 50, //Object detection trace
    DT_ID_SVP_NNIE     = 51,
    DT_ID_SVP_DSP      = 52,
    DT_ID_DPU_RECT     = 53,
    DT_ID_DPU_MATCH    = 54,

    DT_ID_MOTIONSENSER = 55,

    DT_ID_BUTT,
} DT_MOD_ID_E;
    
typedef enum _VIDEO_FIELD_E
{
    DT_VIDEO_FIELD_TOP         = 0x1,    /* even field */
    DT_VIDEO_FIELD_BOTTOM      = 0x2,    /* odd field */
    DT_VIDEO_FIELD_INTERLACED  = 0x3,    /* two interlaced fields */
    DT_VIDEO_FIELD_FRAME       = 0x4,    /* frame */

    DT_VIDEO_FIELD_BUTT
} DT_VIDEO_FIELD_E;
    
 /* we ONLY define picture format used, all unused will be deleted!*/
typedef enum _PIXEL_FORMAT_E
{
    DT_PIXEL_FORMAT_RGB_444 = 0,
    DT_PIXEL_FORMAT_RGB_555,
    DT_PIXEL_FORMAT_RGB_565,
    DT_PIXEL_FORMAT_RGB_888,

    DT_PIXEL_FORMAT_BGR_444,
    DT_PIXEL_FORMAT_BGR_555,
    DT_PIXEL_FORMAT_BGR_565,
    DT_PIXEL_FORMAT_BGR_888,

    DT_PIXEL_FORMAT_ARGB_1555,
    DT_PIXEL_FORMAT_ARGB_4444,
    DT_PIXEL_FORMAT_ARGB_8565,
    DT_PIXEL_FORMAT_ARGB_8888,

    DT_PIXEL_FORMAT_ABGR_1555,
    DT_PIXEL_FORMAT_ABGR_4444,
    DT_PIXEL_FORMAT_ABGR_8565,
    DT_PIXEL_FORMAT_ABGR_8888,

    DT_PIXEL_FORMAT_RGB_BAYER_8BPP,
    DT_PIXEL_FORMAT_RGB_BAYER_10BPP,
    DT_PIXEL_FORMAT_RGB_BAYER_12BPP,
    DT_PIXEL_FORMAT_RGB_BAYER_14BPP,
    DT_PIXEL_FORMAT_RGB_BAYER_16BPP,


    DT_PIXEL_FORMAT_YVU_PLANAR_422,
    DT_PIXEL_FORMAT_YVU_PLANAR_420,
    DT_PIXEL_FORMAT_YVU_PLANAR_444,

    DT_PIXEL_FORMAT_YVU_SEMIPLANAR_422,
    DT_PIXEL_FORMAT_YVU_SEMIPLANAR_420,
    DT_PIXEL_FORMAT_YVU_SEMIPLANAR_444,

    DT_PIXEL_FORMAT_YUV_SEMIPLANAR_422,
    DT_PIXEL_FORMAT_YUV_SEMIPLANAR_420,
    DT_PIXEL_FORMAT_YUV_SEMIPLANAR_444,

    DT_PIXEL_FORMAT_UYVY_PACKAGE_422,
    DT_PIXEL_FORMAT_YUYV_PACKAGE_422,
    DT_PIXEL_FORMAT_VYUY_PACKAGE_422,

    DT_PIXEL_FORMAT_YUV_400,
    DT_PIXEL_FORMAT_UV_420,


    /* SVP data format */
    DT_PIXEL_FORMAT_BGR_888_PLANAR,
    DT_PIXEL_FORMAT_HSV_888_PACKAGE,
    DT_PIXEL_FORMAT_HSV_888_PLANAR,
    DT_PIXEL_FORMAT_LAB_888_PACKAGE,
    DT_PIXEL_FORMAT_LAB_888_PLANAR,
    DT_PIXEL_FORMAT_S8C1,
    DT_PIXEL_FORMAT_S8C2_PACKAGE,
    DT_PIXEL_FORMAT_S8C2_PLANAR,
    DT_PIXEL_FORMAT_S16C1,
    DT_PIXEL_FORMAT_U8C1,
    DT_PIXEL_FORMAT_U16C1,
    DT_PIXEL_FORMAT_S32C1,
    DT_PIXEL_FORMAT_U32C1,
    DT_PIXEL_FORMAT_U64C1,
    DT_PIXEL_FORMAT_S64C1,

    DT_PIXEL_FORMAT_BUTT
} DT_PIXEL_FORMAT_E; 

typedef enum _VIDEO_FORMAT_E
{
    DT_VIDEO_FORMAT_LINEAR = 0,       /* nature video line */
    DT_VIDEO_FORMAT_TILE_64x16,       /* tile cell: 64pixel x 16line */
    DT_VIDEO_FORMAT_TILE_16x8,        /* tile cell: 16pixel x 8line */
    DT_VIDEO_FORMAT_LINEAR_DISCRETE,  /* The data bits are aligned in bytes */
    DT_VIDEO_FORMAT_BUTT
} DT_VIDEO_FORMAT_E;

typedef enum _COMPRESS_MODE_E
{
    DT_COMPRESS_MODE_NONE = 0,   /* no compress */
    DT_COMPRESS_MODE_SEG,        /* compress unit is 256x1 bytes as a segment.*/
    DT_COMPRESS_MODE_TILE,       /* compress unit is a tile.*/
    DT_COMPRESS_MODE_LINE,       /* compress unit is the whole line.  raw for VI  */
    DT_COMPRESS_MODE_FRAME,      /* compress unit is the whole frame. YUV for VI(3DNR), RGB for TDE(write)/VO(read) */

    DT_COMPRESS_MODE_BUTT
} DT_COMPRESS_MODE_E;

typedef enum _DYNAMIC_RANGE_E
{
    DT_DYNAMIC_RANGE_SDR8 = 0,
    DT_DYNAMIC_RANGE_SDR10,
    DT_DYNAMIC_RANGE_HDR10,
    DT_DYNAMIC_RANGE_HLG,
    DT_DYNAMIC_RANGE_SLF,
    DT_DYNAMIC_RANGE_XDR,
    DT_DYNAMIC_RANGE_BUTT
} DT_DYNAMIC_RANGE_E;

typedef enum _COLOR_GAMUT_E
{
    DT_COLOR_GAMUT_BT601 = 0,
    DT_COLOR_GAMUT_BT709,
    DT_COLOR_GAMUT_BT2020,
    DT_COLOR_GAMUT_USER,
    DT_COLOR_GAMUT_BUTT
} DT_COLOR_GAMUT_E;

typedef struct _VIDEO_SUPPLEMENT_S
{
    Uint64_t   u64JpegDCFPhyAddr;
    Uint64_t   u64IspInfoPhyAddr;
    Uint64_t   u64LowDelayPhyAddr;
    Uint64_t   u64MotionDataPhyAddr;
    Uint64_t   u64FrameDNGPhyAddr;

    DT_VOID* ATTRIBUTE pJpegDCFVirAddr;        /* JPEG_DCF_S, used in JPEG DCF */
    DT_VOID* ATTRIBUTE pIspInfoVirAddr;        /* ISP_FRAME_INFO_S, used in ISP debug, when get raw and send raw */
    DT_VOID* ATTRIBUTE pLowDelayVirAddr;       /* used in low delay */
    DT_VOID* ATTRIBUTE pMotionDataVirAddr;     /* vpss 3dnr use: gme motion data, Filter motion data, gyro data.*/
    DT_VOID* ATTRIBUTE pFrameDNGVirAddr;
} DT_VIDEO_SUPPLEMENT_S;

typedef struct _VIDEO_FRAME_S
{
    Uint32_t              u32Width;
    Uint32_t              u32Height;
    DT_VIDEO_FIELD_E       enField;
    DT_PIXEL_FORMAT_E      enPixelFormat;
    DT_VIDEO_FORMAT_E      enVideoFormat;
    DT_COMPRESS_MODE_E     enCompressMode;
    DT_DYNAMIC_RANGE_E     enDynamicRange;
    DT_COLOR_GAMUT_E       enColorGamut;
    Uint32_t              u32HeaderStride[3];
    Uint32_t              u32Stride[3];
    Uint32_t              u32ExtStride[3];

    Uint64_t              u64HeaderPhyAddr[3];
    Uint64_t              u64HeaderVirAddr[3];
    Uint64_t              u64PhyAddr[3];
    Uint64_t              u64VirAddr[3];
    Uint64_t              u64ExtPhyAddr[3];
    Uint64_t              u64ExtVirAddr[3];

    Int16_t              s16OffsetTop;        /* top offset of show area */
    Int16_t              s16OffsetBottom;    /* bottom offset of show area */
    Int16_t              s16OffsetLeft;        /* left offset of show area */
    Int16_t              s16OffsetRight;        /* right offset of show area */

    Uint32_t              u32MaxLuminance;
    Uint32_t              u32MinLuminance;

    Uint32_t              u32TimeRef;
    Uint64_t              u64PTS;

    Uint64_t              u64PrivateData;
    Uint32_t              u32FrameFlag;     /* FRAME_FLAG_E, can be OR operation. */
    DT_VIDEO_SUPPLEMENT_S  stSupplement;
} DT_VIDEO_FRAME_S;

typedef struct _VIDEO_FRAME_INFO_S
{

    DT_VIDEO_FRAME_S stVFrame;
    Uint32_t         u32PoolId;
    DT_MOD_ID_E      enModId;
}DT_VIDEO_FRAME_INFO_S;

#if 0
typedef union  
{
    DT_VIDEO_FRAME_INFO_S dtVideoFrameInfos;
}DT_FRAME_INFO_S;
#endif

class Stream: public detu_infra::Shared_ptr<unsigned char>
{
public:
	Stream(): Shared_ptr(), fSize(0u) {};
	Stream(unsigned char* ptr, Uint32_t size): Shared_ptr(ptr), fSize(size) {};

	const void* getAddr() {return get();};

	const Uint32_t getSize() {return fSize;};
private:
	Uint32_t fSize;
};

class Frame
{
public:
	Frame():fSize(0u), buf(nullptr) {};
	Frame(unsigned char* ptr, Uint32_t size):fSize(size), buf(ptr) {};

	const void* getAddr() {return buf;};

	const Uint32_t getSize() {return fSize;};
private:
	Uint32_t fSize;
	unsigned char *buf;
};

}
#endif